<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
      <el-form-item label="岗位关键字" prop="keywords">
        <el-input
          v-model="queryParams.keywords"
          placeholder="请输入岗位关键字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="招聘联系人" prop="humanName">
        <el-input
          v-model="queryParams.humanName"
          placeholder="请输入招聘联系人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地区" prop="area">
        <el-select v-model="queryParams.area" placeholder="请选择地区" clearable size="small">
          <el-option
            v-for="dict in areaOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学历" prop="education">
        <el-select v-model="queryParams.education" placeholder="请选择学历" clearable size="small">
          <el-option
            v-for="dict in educationOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="经验" prop="experience">
        <el-input
          v-model="queryParams.experience"
          placeholder="请输入经验"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位名称" prop="recruitName">
        <el-input
          v-model="queryParams.recruitName"
          placeholder="请输入岗位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['member:recruit:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['member:recruit:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['member:recruit:remove']"
        >删除</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="recruitList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="岗位名称" align="center" prop="recruitName" />
      <el-table-column label="招聘联系人" align="center" prop="contactsName" />
      <el-table-column label="招聘人头像" align="center" prop="contactsAvatar">
        <template slot-scope="scope">
          <el-image :src="imgpre+ scope.row.contactsAvatar"  :preview-src-list="showImg(scope.row.contactsAvatar)"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column label="地区" align="center" prop="area" :formatter="areaFormat" />
      <el-table-column label="学历" align="center" prop="education" :formatter="educationFormat" />
      <el-table-column label="经验" align="center" prop="experience" />
      <el-table-column label="工资范围" align="center" prop="wagesDistance" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="岗位关键字" align="center" prop="keywords" />
    <!--  <el-table-column label="任职要求" align="center" prop="ask" />-->
      <el-table-column label="职责" align="center" prop="responsibility" />
    <!--  <el-table-column label="坐标位置" align="center" prop="coordinate" />-->
    <!--  <el-table-column label="岗位名称" align="center" prop="id" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['member:recruit:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['member:recruit:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改招聘模块对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">

        <el-form-item label="岗位名称" prop="recruitName">
          <el-input v-model="form.recruitName" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="招聘人头像" prop="contactsAvatar">
        <!--  <el-upload
            class="avatar-uploader"
            :action="uploadImgUrl"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <img v-if="form.contactsAvatar" :src="imgpre +form.contactsAvatar" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>-->
          <el-upload
            class="avatar-uploader"
            :action="uploadImgUrl"
            :show-file-list="false"
            accept=".jpg,.jpeg,.png,.gif,.bmp"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatarrecruit">
            <i v-else class="el-icon-plus avatar-uploader-iconrecruit"></i>
            <div slot="tip" class="el-upload-tip">.支持jpg、png、gif、jpeg格式的图片</div>
            <div slot="tip" class="el-upload-tip">.图片尺寸220PX*220PX，文件大小不超过2M</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="招聘联系人" prop="contactsName">
          <el-input v-model="form.contactsName" placeholder="请输入招聘联系人" />
        </el-form-item>
        <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="地区">
          <el-select v-model="form.area" placeholder="请选择地区">
            <el-option
              v-for="dict in areaOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学历">
          <el-select v-model="form.education" placeholder="请选择学历">
            <el-option
              v-for="dict in educationOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="经验" prop="experience">
          <el-input v-model="form.experience"  placeholder="请输入经验" maxlength="6" show-word-limit />
        </el-form-item>
        <el-form-item label="工资范围" prop="wagesDistance">
          <el-input v-model="form.wagesDistance" placeholder="请输入工资范围" maxlength="6" show-word-limit />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="岗位关键字" prop="keywords">
          <el-input v-model="form.keywords" placeholder="请输入岗位关键字" maxlength="10" show-word-limit/>
        </el-form-item>
        <el-form-item label="职责" prop="responsibility">
          <el-input v-model="form.responsibility" placeholder="请输入职责" />
        </el-form-item>
        <el-form-item label="任职要求" prop="ask">
          <el-input v-model="form.ask" type="textarea"  :autosize="{ minRows: 2, maxRows: 8 }" placeholder="请输入任职要求" />
        </el-form-item>


        <el-form-item label="坐标位置" prop="coordinate">
          <el-input v-model="form.coordinate" placeholder="请输入坐标位置" />
        </el-form-item>




      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecruit, getRecruit, delRecruit, addRecruit, updateRecruit, exportRecruit } from "@/api/member/recruit";
import defaultSettings from '@/settings'
export default {
  name: "Recruit",
  data() {
    return {
      imgpre: defaultSettings.ossPreview,
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload/oss", // 上传的图片服务器地址
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 招聘模块表格数据
      recruitList: [],
      imageUrl: '',
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 地区字典
      areaOptions: [],
      // 学历字典
      educationOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn:'id',
        isAsc:'desc',
        bak3: undefined,
        bak2: undefined,
        bak1: undefined,
        keywords: undefined,
        ask: undefined,
        responsibility: undefined,
        humanName: undefined,
        coordinate: undefined,
        address: undefined,
        area: undefined,
        education: undefined,
        experience: undefined,
        wagesDistance: undefined,
        recruitName: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        keywords: [
          { required: true, message: "岗位关键字不能为空", trigger: "blur" }
        ],
        ask: [
          { required: true, message: "任职要求不能为空", trigger: "blur" }
        ],
        responsibility: [
          { required: true, message: "职责不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ],
        area: [
          { required: true, message: "地区不能为空", trigger: "blur" }
        ],
        education: [
          { required: true, message: "学历不能为空", trigger: "blur" }
        ],
        experience: [
          { required: true, message: "经验不能为空", trigger: "blur" }
        ],
        wagesDistance: [
          { required: true, message: "工资范围不能为空", trigger: "blur" }
        ],
        recruitName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_area").then(response => {
      this.areaOptions = response.data;
    });
    this.getDicts("education").then(response => {
      this.educationOptions = response.data;
    });
  },
  methods: {
   /* beforeAvatarUpload(file) {
      console.log(file.type.indexOf("image/jpeg,image/png"))
      const isJPG =( file.type === 'image/jpeg'||file.type === 'image/png'||file.type === 'image/tif');
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 图片jpg、png、tif 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    handleAvatarSuccess(res) {
      this.form.contactsAvatar =  res.imgUrl
      console.log(this.form.contactsAvatar)
    },*/

    handleAvatarSuccess(res, file) {
      this.imageUrl =this.imgpre+res.imgUrl;
      this.form.contactsAvatar=res.imgUrl;
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isLt2M;
    },
    //放大图片
    showImg(e){
      let array=[];
      array.push(this.imgpre+e);
      return array;
    },
    /** 查询招聘模块列表 */
    getList() {
      this.loading = true;
      listRecruit(this.queryParams).then(response => {
        this.recruitList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 地区字典翻译
    areaFormat(row, column) {
      return this.selectDictLabel(this.areaOptions, row.area);
    },
    // 学历字典翻译
    educationFormat(row, column) {
      return this.selectDictLabel(this.educationOptions, row.education);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        updateTime: undefined,
        updateBy: undefined,
        createTime: undefined,
        createBy: undefined,
        bak3: undefined,
        bak2: undefined,
        bak1: undefined,
        keywords: undefined,
        ask: undefined,
        responsibility: undefined,
        humanName: undefined,
        coordinate: undefined,
        address: undefined,
        area: undefined,
        education: undefined,
        experience: undefined,
        wagesDistance: undefined,
        recruitName: undefined,
        id: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加招聘模块";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecruit(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改招聘模块";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateRecruit(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addRecruit(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除招聘模块编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRecruit(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有招聘模块数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportRecruit(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-iconrecruit {
    font-size: 28px;
    color: #8c939d;
    width: 110px;
    height: 110px;
    line-height: 110px;
    text-align: center;
  }
  .avatarrecruit {
    width: 110px;
    height: 110px;
    display: block;
  }
  .el-upload-tip{
    color: #AAAAAA;
    line-height: 1.7;
    font-size: 12px;
  }
</style>
